import {Component, OnInit, ViewChild} from '@angular/core';
import {ModalDirective} from "ngx-bootstrap";
import {HttpService} from "../../../lib/service/http.service";
import {adSystemApiUrl} from "../../../../config/api";
import {NzModalService} from "ng-zorro-antd";

@Component({
  selector: 'app-list',
  templateUrl: './list.component.html',
  styleUrls: ['./list.component.scss']
})
export class ListComponent implements OnInit {


  searchData = '';
  withDrawList = [];
  userName: string;
  psd: string;
  password_again: string;
  operateId: number;  // 当前正在操作的账号ID
  resetPsd: string;
  resetPsdAgain: string;
  status = '';
  actived_order_no = '';

  type: string;
  message: string;
  isShow = true;
  totalItems: number;
  currentPage: number = 1;
  itemsPerPage: number = 20;
  url = `${adSystemApiUrl}/v1/admin/tuike/tuiker/withdraw_list`;
  _isSpinning = false;

  @ViewChild('addClientModal') public addClientModal: ModalDirective;
  @ViewChild('resetPsdModal') public resetPsdModal: ModalDirective;

  constructor(private httpService: HttpService,private confirmServ: NzModalService) {
  }

  ngOnInit() {
    this.getWithDrawList(1);
  }

  //重置
  reset(){
    this.searchData = '';
    this.getWithDrawList(1);
  }
  //搜索
  search(){
    this.getWithDrawList(1);
  }

  showConfirm() {
    this.confirmServ.confirm({
      title: '温馨提示',
      content: '<b>您确定要同意申请吗?</b>',
      onOk:() => {
        let url = `${adSystemApiUrl}/v1/admin/member_point_order/withdraw`;
        this.httpService.httpPostAuth(url,{type:3, order_no:this.actived_order_no}).subscribe( res => {
          console.log(res);
        })
      },
      onCancel() {
      }
    });
  }


    getWithDrawList(page) {
    this._isSpinning = true;
    this.httpService.httpPostAuth(this.url + '?page=' + page, {}).subscribe(res => {
      if (res.code == 200) {
        this._isSpinning = false;
        this.withDrawList = res.data.data;
        this.totalItems = res.data.total;
      }
    })
  }

  pageChanged(event: any): void {
    window.scrollTo(0,0);
    this.getWithDrawList(event.page);
  }

}
